package org.dyk.mallmanagementsystem.repository;

import org.dyk.mallmanagementsystem.model.Orders;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface OrdersRepository extends CrudRepository<Orders, Integer> {
    //查询所有订单信息 分页
    public Page<Orders> findAll(Pageable pageable);

    //查询所有订单信息
    public List<Orders> findAll();

    //根据 主键 获取订单信息
    public Orders findByOid(int oid);

    //根据 商品ID 获取订单信息
    public List<Orders> findByGid(int gid);

    //根据 用户ID 获取订单信息
    public List<Orders> findByUid(int uid);

    //自定义查询订单
    @Query(nativeQuery = true, value = "select * from orders as o where " +
            "if(?1 != 10000 , oid = ?1, 1 = 1) " +
            "and if(?2 != 4, orders_state = ?2, 1 = 1)")
    public List<Orders> selectOrders(int oid, int ordersState);
}
